home *** CD-ROM | disk | FTP | other *** search
/ Inventor Labs: Technology / INVENTORLABS_TECHNOLOGY.BIN / pc / files / gears.dir / 00210_Script_Gear Manger Parent < prev    next >
Text File  |  1997-05-26  |  14KB  |  367 lines

  1. --o Gear Mgr parent
  2.  
  3.  
  4.  
  5. -- gGearMgrParent
  6.  
  7. property pActiveGearList, pGearScript
  8. property pActiveSpeed
  9.  
  10. property pMaxGears, pCurrNumOfGears
  11. property pNewGearStartSprite, pGearCastLst, pNextAvailGearSprite
  12. property pAvailGearStartSprite, pActiveGearRects, pCurrentDragCast, pDraggingGearSize
  13. property pSnapped, pNeighborHorz, pNeighborVert, pNeighborSize, pDragGearStep
  14. property pRadius, pDistance, pSnapSide, pSliderActive, pCurrTempo
  15.  
  16. property pLeftSliderEdge, pSliderSprite,pGridContraintSprite, pAjoiningEdge, pHorzStick, pVertStick
  17.  
  18. property pScreenOnGear, pScreenSprite, pScreenDirection, pScreenFirstCast, pScreenLastCast,pGearInc
  19. property pScreenRefresh, pScreenCurrCast, pDriveGearObj
  20.  
  21. global gGearMgrParent
  22. ------------------------------------------------------------------------------------------------------------
  23. on mInit me
  24.   
  25.   set pGearScript = script "gear parent"
  26.   
  27.   set SmallGearCast = [the number of cast "ISMGR00000", the number of cast "ISMGR00023"]
  28.   set MidGearCast = [the number of cast "IGRMD00000", the number of cast "IGRMD00035"]
  29.   set LargeGearCast = [the number of cast "IGRLG00000", the number of cast "IGRLG00047"]
  30.   set pGearCastLst =[LargeGearCast, MidGearCast, SmallGearCast]
  31.   set pRadius = [#small: 25,#Middle:36,#Large:47]
  32.   
  33.   set pGridContraintSprite = 8
  34.   set pMaxGears = 8
  35.   set pCurrNumOfGears = 0
  36.   set pAvailGearStartSprite  = 9
  37.   set pNextAvailGearSprite = pAvailGearStartSprite
  38.   set pNewGearStartSprite = 5
  39.   
  40.   set pSnapped = FALSE
  41.   set pActiveGearList = []
  42.   set pActiveGearRects = []
  43.   set pSliderActive = FALSE
  44.   set pSliderSprite = 22
  45.   set pCurrTempo = 10
  46.   set pScreenOnGear = FALSE
  47.   set pScreenSprite = 19
  48.   
  49.   set pScreenDirection = 0
  50.   set pScreenFirstCast = the number of cast "gearmv00000"
  51.   set pScreenLastCast = the number of cast "gearmv00060"
  52.   set pGearInc = 0
  53.   set pScreenRefresh = 0
  54.   set pScreenCurrCast = pScreenFirstCast
  55.   
  56.   
  57.   return( me )
  58.   
  59. end mInit
  60. ------------------------------------------------------------------------------------------------------------
  61. on mActivate me
  62.   
  63.   puppettempo pCurrTempo
  64.   set pCurrNumOfGears = 1
  65.   set whatcast = [the number of cast "IGRDW00000", the number of cast "IGRDW00023"]
  66.   set pDriveGearObj =  birth( pGearScript,#small,whatcast,pNextAvailGearSprite,1,the number of cast "IGRDW00000",4,0)
  67.   
  68.   set pActiveGearList = [pDriveGearObj]
  69.   set pNextAvailGearSprite = pNextAvailGearSprite + 1
  70.   
  71.   set pLeftSliderEdge = the left of sprite (pSliderSprite -1)
  72.   puppetsprite pSliderSprite, TRUE
  73.   puppetsprite pScreenSprite, TRUE
  74.   set the constraint of sprite pScreenSprite = pScreenSprite - 1
  75.   
  76. end mActivate
  77. ------------------------------------------------------------------------------------------------------------
  78. on mclose me
  79.   
  80.   repeat with spriteNum = pAvailGearStartSprite to pNextAvailGearSprite 
  81.     puppetsprite spriteNum, false
  82.     set the constraint of sprite spriteNum = 0
  83.   end repeat
  84.   puppetsprite pSliderSprite, False
  85.   puppetsprite pScreenSprite, False
  86.   set the constraint of sprite pScreenSprite = 0
  87.   
  88. end mclose
  89. ------------------------------------------------------------------------------------------------------------
  90. on mSetSpeed me
  91.   
  92.   set pSliderActive = TRUE
  93.   when mouseup then mReleaseSlider( gGearMgrParent )
  94.   
  95. end mSetSpeed
  96. ------------------------------------------------------------------------------------------------------------
  97. on mReleaseSlider me
  98.   
  99.   when mouseup then
  100.   set pSliderActive = FALSE
  101.   
  102. end mReleaseSlider
  103. ------------------------------------------------------------------------------------------------------------
  104. on mPerform me
  105.   
  106.   if (pCurrTempo >= 7) then
  107.     repeat with gear in pActiveGearList
  108.       mPerform( gear )
  109.     end repeat
  110.   end if
  111.   
  112.   if pSliderActive then
  113.     set newh = the mouseh
  114.     if newh > 600 then set newh = 600
  115.     else if newh < 512 then set newh = 512
  116.     set the loch of sprite pSliderSprite = newh
  117.     set pCurrTempo = integer((the loch of sprite pSliderSprite - pLeftSliderEdge) * .5) + 5
  118.     
  119.     if pCurrTempo > 45 then set pCurrTempo = 120
  120.     puppettempo pCurrTempo
  121.     
  122.   end if
  123.   
  124.   if pcurrTempo <= 6 then set pActiveSpeed = 0
  125.   else set pActiveSpeed = 1
  126.   
  127.   if pScreenOnGear and pActiveSpeed then
  128.     
  129.     set pScreenRefresh = pScreenRefresh + 1
  130.     if (pScreenRefresh mod pGearInc) = 0 then
  131.       set newcast = pScreenCurrCast + 1* pScreenDirection
  132.       if newcast > pScreenLastCast then set newcast = pScreenFirstCast
  133.       else if newcast < pScreenFirstCast then set newcast = pScreenLastCast
  134.       set pScreenCurrCast = newcast
  135.       set the castnum of sprite pScreenSprite = pScreenCurrCast
  136.     end if
  137.     
  138.   end if
  139.   
  140.   go the frame
  141.   
  142. end mPerform
  143. ------------------------------------------------------------------------------------------------------------
  144. on mNewGear me
  145.   
  146.   if (pCurrNumOfGears < pMaxGears) then 
  147.     set whatGearCast = getat(pGearCastLst, (the clickon - pNewGearStartSprite) + 1)
  148.     birth( pGearScript, whatGearCast,pNextAvailGearSprite,0)
  149.     set pNextAvailGearSprite = pNextAvailGearSprite + 1
  150.     set pCurrNumOfGears = pCurrNumOfGears + 1
  151.   end if
  152.   
  153. end mNewGear
  154. ------------------------------------------------------------------------------------------------------------
  155. on mDragGear me
  156.   
  157.   
  158.   if (pCurrNumOfGears < pMaxGears) then 
  159.     
  160.     set pDragginGear = (the clickon - pNewGearStartSprite) + 1  -- 1 is large, 2, is medium
  161.     set CastRange =  getat(pGearCastLst, pDragginGear)
  162.     set  pCurrentDragCast = getat(CastRange , 1)  -- return first cast in Cycle for that gear
  163.     set the castnum of sprite pNextAvailGearSprite = pCurrentDragCast
  164.     set pDragGearStep = 0
  165.     set pDraggingGearSize = getat([#Large,#Middle,#small],pDragginGear)
  166.     set pSnapped = FALSE
  167.     
  168.     repeat while the mousedown
  169.       
  170.       set MouseH = the mouseh
  171.       set MouseV = the mousev
  172.       set MousePnt = point(MouseH, MouseV)
  173.       
  174.       if rollover(pGridContraintSprite) then set the constraint of sprite pNextAvailGearSprite to pGridContraintSprite
  175.       
  176.       set SpriteToCheck = pAvailGearStartSprite
  177.       set found = FALSE
  178.       
  179.       repeat while (not found) and (SpriteToCheck < pNextAvailGearSprite ) and not pSnapped
  180.         
  181.         if sprite pNextAvailGearSprite intersects SpriteToCheck then
  182.           set NeighborGearObj = getat(pActiveGearList,(SpriteToCheck - pAvailGearStartSprite  + 1))
  183.           mSnapNeighbor( me, mGetNeighborCords(NeighborGearObj), MouseH, MouseV)
  184.           set found = TRUE
  185.         else set SpriteToCheck = SpriteToCheck + 1
  186.         
  187.       end repeat
  188.       
  189.       if pSnapped then 
  190.         
  191.         if abs(pNeighborHorz - MouseH) > pHorzStick then 
  192.           set the loch of sprite pNextAvailGearSprite = MouseH
  193.           set pSnapped = FALSE
  194.         else if abs(pNeighborVert - MouseV) > pVertStick then
  195.           set the locv of sprite pNextAvailGearSprite = MouseV
  196.           set pSnapped = FALSE
  197.         end if
  198.         
  199.       else if not found then 
  200.         set the loch of sprite pNextAvailGearSprite = MouseH
  201.         set the locv of sprite pNextAvailGearSprite = MouseV
  202.       end if
  203.       
  204.       updatestage
  205.       
  206.     end repeat  -- Mousedown
  207.     
  208.     if pSnapped then 
  209.       set direction =  -1 * mGetDirection( NeighborGearObj )
  210.       set NewGear = birth( pGearScript,pDraggingGearSize,CastRange,pNextAvailGearSprite,¼
  211.                                                           direction,pCurrentDragCast, pAjoiningEdge,NeighborGearObj)
  212.       set pCurrNumOfGears = pCurrNumOfGears + 1
  213.       append( pActiveGearList,NewGear)
  214.       set pNextAvailGearSprite = pNextAvailGearSprite + 1
  215.       mSetNeighbor( NeighborGearObj, pSnapSide, NewGear)
  216.     else set the constraint of sprite pNextAvailGearSprite to 0
  217.     mMoveScreen (me, TRUE)
  218.   end if
  219.   
  220.   
  221. end mDragGear
  222. ------------------------------------------------------------------------------------------------------------
  223. on mReset me
  224.   
  225.   repeat with spritenum  =  (pAvailGearStartSprite + 1) to pNextAvailGearSprite
  226.     puppetsprite spritenum, false
  227.     set the constraint of sprite spritenum = 0
  228.   end repeat
  229.   set pActiveGearList = [pDriveGearObj]
  230.   set pNextAvailGearSprite = pAvailGearStartSprite + 1
  231.   set pSnapped = FALSE
  232.   set pCurrNumOfGears = 1
  233.   set pScreenOnGear = FALSE
  234.   mClearAllNeighbor ( pDriveGearObj )
  235.   mSetNeighbor ( pDriveGearObj , 3)
  236.   set the rect of sprite pScreenSprite = rect(397, 44, 545, 162)
  237.   
  238. end mReset
  239. ------------------------------------------------------------------------------------------------------------
  240. on mRemoveGear me
  241.   
  242.   if the doubleclick and (the clickon = pNextAvailGearSprite - 1) then 
  243.     set the castnum of sprite (pNextAvailGearSprite - 1) = 0
  244.     set whatgear = getat(pActiveGearList, count(pActiveGearList))
  245.     mInformNeighbors( whatgear )
  246.     deleteat(pActiveGearList, count(pActiveGearList))
  247.     puppetsprite (pNextAvailGearSprite - 1), FALSE
  248.     set pNextAvailGearSprite = pNextAvailGearSprite -1
  249.     set the constraint of sprite pNextAvailGearSprite = 0
  250.     set pCurrNumOfGears = pCurrNumOfGears - 1
  251.     mMoveScreen (me, TRUE)
  252.   end if
  253.   
  254. end mRemoveGear
  255. ------------------------------------------------------------------------------------------------------------
  256. on mSnapNeighbor me, GearInfo, MouseH, MouseV
  257.   
  258.   set pNeighborHorz = getat( GearInfo, 1)
  259.   set pNeighborVert = getat( GearInfo, 2)
  260.   set pNeighborSize = getat( GearInfo, 3)
  261.   set pNeighborStep = getat( GearInfo, 4)
  262.   set pNeighborAvialSlots = getat( GearInfo, 5)
  263.   
  264.   ---- rotate to align teeth
  265.   if (pDragGearStep = pNeighborStep) or (pDragGearStep + pNeighborStep = 3) then
  266.     set pDragGearStep = (pDragGearStep + 1) mod 3
  267.     set pCurrentDragCast = pCurrentDragCast + 1
  268.     set the castnum of sprite pNextAvailGearSprite = pCurrentDragCast
  269.   end if
  270.   ----
  271.   
  272.   set pDistance = (getprop(pRadius,pNeighborSize) + getprop(pRadius,pDraggingGearSize))
  273.   set snapDistance =  pDistance - 4
  274.   
  275.   if abs( MouseH - pNeighborHorz) >= abs( MouseV - pNeighborVert)  then
  276.     
  277.     if (MouseH <= pNeighborHorz)  and (getat(pNeighborAvialSlots,1) = 1) then
  278.       set the loch of sprite pNextAvailGearSprite = (pNeighborHorz - snapDistance)
  279.       set the locv of sprite pNextAvailGearSprite = pNeighborVert
  280.       set pSnapSide = 1
  281.     else if (MouseH > pNeighborHorz)  and (getat(pNeighborAvialSlots,3) = 1) then 
  282.       set the loch of sprite pNextAvailGearSprite = (pNeighborHorz + snapDistance)
  283.       set the locv of sprite pNextAvailGearSprite = pNeighborVert
  284.       set pSnapSide = 3
  285.     end if
  286.     set pHorzStick = pDistance
  287.     set pVertStick = pDistance --getprop(pRadius,pDraggingGearSize)/4
  288.     
  289.   else
  290.     
  291.     if (MouseV <= pNeighborVert)  and (getat(pNeighborAvialSlots,2) = 1) then 
  292.       set the locV of sprite pNextAvailGearSprite = (pNeighborVert - snapDistance)
  293.       set the locH of sprite pNextAvailGearSprite = pNeighborHorz
  294.       set pSnapSide = 2
  295.     else if (MouseV > pNeighborVert) and (getat(pNeighborAvialSlots,4) = 1) then 
  296.       set the locV of sprite pNextAvailGearSprite = (pNeighborVert + snapDistance)
  297.       set the locH of sprite pNextAvailGearSprite = pNeighborHorz
  298.       set pSnapSide = 4
  299.     end if
  300.     
  301.     set pHorzStick = pDistance --getprop(pRadius,pDraggingGearSize)/4
  302.     set pVertStick = pDistance
  303.     
  304.   end if
  305.   
  306.   set pAjoiningEdge = (pSnapSide  + 2) Mod 5
  307.   if pAjoiningEdge = 0 then set pAjoiningEdge = 1
  308.   set pSnapped = TRUE
  309.   
  310.   updatestage
  311.   
  312.   
  313. end mSnapNeighbor
  314. ------------------------------------------------------------------------------------------------------------
  315. on mMoveScreen me, GearPlaced
  316.   
  317.   
  318.   if not GearPlaced then
  319.     set Hoffset = abs((the loch of sprite pScreenSprite) - the mouseH)
  320.     set Voffset = abs((the locv of sprite pScreenSprite) - the mouseV)
  321.   end if
  322.   
  323.   
  324.   repeat while the mousedown or GearPlaced
  325.     
  326.     if GearPlaced then set GearPlaced = FALSE
  327.     else
  328.       set the loch of sprite pScreenSprite = (the mouseH - Hoffset)
  329.       set the locv of  sprite pScreenSprite = (the mouseV - Voffset )
  330.       updatestage
  331.     end if
  332.     
  333.     
  334.     set SpriteToCheck = pAvailGearStartSprite
  335.     set found = FALSE
  336.     
  337.     repeat while (not found) and (SpriteToCheck < pNextAvailGearSprite )
  338.       
  339.       if sprite pScreenSprite intersects SpriteToCheck then
  340.         set NeighborGearObj = getat(pActiveGearList,(SpriteToCheck - pAvailGearStartSprite  + 1))
  341.         set gearInfo = mGetNeighborCords(NeighborGearObj)
  342.         set pNeighborSize = getat( GearInfo, 3)
  343.         set pNeighborVert = getat( GearInfo, 2)
  344.         set NeighborRadius = getprop(pRadius,pNeighborSize)
  345.         set maxlocv = pNeighborVert + NeighborRadius
  346.         if the locv of sprite pScreenSprite > maxlocv then 
  347.           set the locv of sprite pScreenSprite = maxlocv
  348.           updatestage
  349.         end if
  350.         
  351.         set pGearInc = getprop([#small:1,#middle:2,#Large:3],pNeighborSize)
  352.         set pScreenRefresh = 0
  353.         set pScreenDirection =  mGetDirection( NeighborGearObj )
  354.         set pScreenOnGear = TRUE
  355.         set Found = TRUE
  356.         
  357.       else 
  358.         set SpriteToCheck = SpriteToCheck + 1
  359.         set pScreenOnGear = FALSE
  360.       end if
  361.       
  362.     end repeat
  363.     
  364.   end repeat
  365.   
  366. end mMoveScreen
  367. ------------------------------------------------------------------------------------------------------------